// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

impl gaxi::prost::ToProto<SetIamPolicyRequest> for iam_v1::model::SetIamPolicyRequest {
    type Output = SetIamPolicyRequest;
    fn to_proto(self) -> std::result::Result<SetIamPolicyRequest, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            resource: self.resource.to_proto()?,
            policy: self.policy.map(|v| v.to_proto()).transpose()?,
            update_mask: self.update_mask.map(|v| v.to_proto()).transpose()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::SetIamPolicyRequest> for SetIamPolicyRequest {
    fn cnv(self) -> std::result::Result<iam_v1::model::SetIamPolicyRequest, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::SetIamPolicyRequest::new()
                .set_resource(self.resource)
                .set_or_clear_policy(self.policy.map(|v| v.cnv()).transpose()?)
                .set_or_clear_update_mask(self.update_mask.map(|v| v.cnv()).transpose()?)
        )
    }
}

impl gaxi::prost::ToProto<GetIamPolicyRequest> for iam_v1::model::GetIamPolicyRequest {
    type Output = GetIamPolicyRequest;
    fn to_proto(self) -> std::result::Result<GetIamPolicyRequest, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            resource: self.resource.to_proto()?,
            options: self.options.map(|v| v.to_proto()).transpose()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::GetIamPolicyRequest> for GetIamPolicyRequest {
    fn cnv(self) -> std::result::Result<iam_v1::model::GetIamPolicyRequest, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::GetIamPolicyRequest::new()
                .set_resource(self.resource)
                .set_or_clear_options(self.options.map(|v| v.cnv()).transpose()?)
        )
    }
}

impl gaxi::prost::ToProto<TestIamPermissionsRequest> for iam_v1::model::TestIamPermissionsRequest {
    type Output = TestIamPermissionsRequest;
    fn to_proto(self) -> std::result::Result<TestIamPermissionsRequest, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            resource: self.resource.to_proto()?,
            permissions: self.permissions
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::TestIamPermissionsRequest> for TestIamPermissionsRequest {
    fn cnv(self) -> std::result::Result<iam_v1::model::TestIamPermissionsRequest, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::TestIamPermissionsRequest::new()
                .set_resource(self.resource)
                .set_permissions(self.permissions.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
        )
    }
}

impl gaxi::prost::ToProto<TestIamPermissionsResponse> for iam_v1::model::TestIamPermissionsResponse {
    type Output = TestIamPermissionsResponse;
    fn to_proto(self) -> std::result::Result<TestIamPermissionsResponse, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            permissions: self.permissions
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::TestIamPermissionsResponse> for TestIamPermissionsResponse {
    fn cnv(self) -> std::result::Result<iam_v1::model::TestIamPermissionsResponse, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::TestIamPermissionsResponse::new()
                .set_permissions(self.permissions.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
        )
    }
}

impl gaxi::prost::ToProto<GetPolicyOptions> for iam_v1::model::GetPolicyOptions {
    type Output = GetPolicyOptions;
    fn to_proto(self) -> std::result::Result<GetPolicyOptions, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            requested_policy_version: self.requested_policy_version.to_proto()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::GetPolicyOptions> for GetPolicyOptions {
    fn cnv(self) -> std::result::Result<iam_v1::model::GetPolicyOptions, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::GetPolicyOptions::new()
                .set_requested_policy_version(self.requested_policy_version)
        )
    }
}

impl gaxi::prost::ToProto<Policy> for iam_v1::model::Policy {
    type Output = Policy;
    fn to_proto(self) -> std::result::Result<Policy, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            version: self.version.to_proto()?,
            bindings: self.bindings
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
            audit_configs: self.audit_configs
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
            etag: self.etag.to_proto()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::Policy> for Policy {
    fn cnv(self) -> std::result::Result<iam_v1::model::Policy, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::Policy::new()
                .set_version(self.version)
                .set_bindings(self.bindings.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
                .set_audit_configs(self.audit_configs.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
                .set_etag(self.etag)
        )
    }
}

impl gaxi::prost::ToProto<Binding> for iam_v1::model::Binding {
    type Output = Binding;
    fn to_proto(self) -> std::result::Result<Binding, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            role: self.role.to_proto()?,
            members: self.members
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
            condition: self.condition.map(|v| v.to_proto()).transpose()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::Binding> for Binding {
    fn cnv(self) -> std::result::Result<iam_v1::model::Binding, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::Binding::new()
                .set_role(self.role)
                .set_members(self.members.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
                .set_or_clear_condition(self.condition.map(|v| v.cnv()).transpose()?)
        )
    }
}

impl gaxi::prost::ToProto<AuditConfig> for iam_v1::model::AuditConfig {
    type Output = AuditConfig;
    fn to_proto(self) -> std::result::Result<AuditConfig, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            service: self.service.to_proto()?,
            audit_log_configs: self.audit_log_configs
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::AuditConfig> for AuditConfig {
    fn cnv(self) -> std::result::Result<iam_v1::model::AuditConfig, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::AuditConfig::new()
                .set_service(self.service)
                .set_audit_log_configs(self.audit_log_configs.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
        )
    }
}

impl gaxi::prost::ToProto<audit_log_config::LogType> for iam_v1::model::audit_log_config::LogType {
    type Output = i32;
    fn to_proto(self) -> std::result::Result<Self::Output, gaxi::prost::ConvertError> {
        self.value().ok_or(gaxi::prost::ConvertError::EnumNoIntegerValue("iam_v1::model::audit_log_config::LogType"))
    }
}

impl gaxi::prost::ToProto<AuditLogConfig> for iam_v1::model::AuditLogConfig {
    type Output = AuditLogConfig;
    fn to_proto(self) -> std::result::Result<AuditLogConfig, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            log_type: self.log_type.to_proto()?,
            exempted_members: self.exempted_members
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::AuditLogConfig> for AuditLogConfig {
    fn cnv(self) -> std::result::Result<iam_v1::model::AuditLogConfig, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::AuditLogConfig::new()
                .set_log_type(self.log_type)
                .set_exempted_members(self.exempted_members.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
        )
    }
}

impl gaxi::prost::ToProto<PolicyDelta> for iam_v1::model::PolicyDelta {
    type Output = PolicyDelta;
    fn to_proto(self) -> std::result::Result<PolicyDelta, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            binding_deltas: self.binding_deltas
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
            audit_config_deltas: self.audit_config_deltas
                .into_iter()
                .map(|v| v.to_proto())
                .collect::<std::result::Result<std::vec::Vec<_>, _>>()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::PolicyDelta> for PolicyDelta {
    fn cnv(self) -> std::result::Result<iam_v1::model::PolicyDelta, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::PolicyDelta::new()
                .set_binding_deltas(self.binding_deltas.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
                .set_audit_config_deltas(self.audit_config_deltas.into_iter().map(|v| v.cnv())
                    .collect::<std::result::Result<std::vec::Vec<_>, _>>()?)
        )
    }
}

impl gaxi::prost::ToProto<binding_delta::Action> for iam_v1::model::binding_delta::Action {
    type Output = i32;
    fn to_proto(self) -> std::result::Result<Self::Output, gaxi::prost::ConvertError> {
        self.value().ok_or(gaxi::prost::ConvertError::EnumNoIntegerValue("iam_v1::model::binding_delta::Action"))
    }
}

impl gaxi::prost::ToProto<BindingDelta> for iam_v1::model::BindingDelta {
    type Output = BindingDelta;
    fn to_proto(self) -> std::result::Result<BindingDelta, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            action: self.action.to_proto()?,
            role: self.role.to_proto()?,
            member: self.member.to_proto()?,
            condition: self.condition.map(|v| v.to_proto()).transpose()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::BindingDelta> for BindingDelta {
    fn cnv(self) -> std::result::Result<iam_v1::model::BindingDelta, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::BindingDelta::new()
                .set_action(self.action)
                .set_role(self.role)
                .set_member(self.member)
                .set_or_clear_condition(self.condition.map(|v| v.cnv()).transpose()?)
        )
    }
}

impl gaxi::prost::ToProto<audit_config_delta::Action> for iam_v1::model::audit_config_delta::Action {
    type Output = i32;
    fn to_proto(self) -> std::result::Result<Self::Output, gaxi::prost::ConvertError> {
        self.value().ok_or(gaxi::prost::ConvertError::EnumNoIntegerValue("iam_v1::model::audit_config_delta::Action"))
    }
}

impl gaxi::prost::ToProto<AuditConfigDelta> for iam_v1::model::AuditConfigDelta {
    type Output = AuditConfigDelta;
    fn to_proto(self) -> std::result::Result<AuditConfigDelta, gaxi::prost::ConvertError> {
        Ok(Self::Output {
            action: self.action.to_proto()?,
            service: self.service.to_proto()?,
            exempted_member: self.exempted_member.to_proto()?,
            log_type: self.log_type.to_proto()?,
        })
    }
}

impl gaxi::prost::FromProto<iam_v1::model::AuditConfigDelta> for AuditConfigDelta {
    fn cnv(self) -> std::result::Result<iam_v1::model::AuditConfigDelta, gaxi::prost::ConvertError> {
        Ok(
            iam_v1::model::AuditConfigDelta::new()
                .set_action(self.action)
                .set_service(self.service)
                .set_exempted_member(self.exempted_member)
                .set_log_type(self.log_type)
        )
    }
}
